#include "internal.h"
#include "Defines.h"
#include "DeviceProperty.h"
#include "PortableDeviceProps.h"
#include "ObjectLock.h"
#include "SensorDdi.h"
#include "Sensor.h"
#include "SensorRegistry.h"
#include "SensorDevice.h"
#include "SensorDevice.tmh"

//
// implement the sensor
//
IMPLEMENT_SENSOR(CSensorDevice);

CSensorDevice::CSensorDevice(void)
{
}

CSensorDevice::~CSensorDevice(void)
{
}

HRESULT CSensorDevice::Init(IWDFDevice *pDevice, CSensorDDI *pSensorDDI)
{
	CObjectLock lock(this);

	//
	// call the base implementation first
	//
	HRESULT hr = CSensor::Init(pDevice, pSensorDDI);
	if(FAILED(hr))
		return hr;

	//
	// add sensor supported properties
	//
	hr = m_Properties.AddProps(DEVPROPS(
		MAKEPROP(WPD_DEVICE_FIRMWARE_VERSION, DEVICE_FIRMWARE_VERSION_VALUE),
		MAKEPROP(WPD_DEVICE_POWER_LEVEL, DEVICE_POWER_LEVEL_VALUE),
		MAKEPROP(WPD_DEVICE_POWER_SOURCE, (ULONG)WPD_POWER_SOURCE_EXTERNAL),
		MAKEPROP(WPD_DEVICE_PROTOCOL, DEVICE_PROTOCOL_VALUE),
		MAKEPROP(WPD_DEVICE_MODEL, DEVICE_MODEL_VALUE),
		MAKEPROP(WPD_DEVICE_SERIAL_NUMBER, DEVICE_SERIAL_NUMBER_VALUE),
		MAKEPROP(WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, (BOOL)DEVICE_SUPPORTS_NONCONSUMABLE_VALUE),
		MAKEPROP(WPD_DEVICE_MANUFACTURER, DEVICE_MANUFACTURER_VALUE),
		MAKEPROP(WPD_DEVICE_FRIENDLY_NAME, DEVICE_FRIENDLY_NAME_VALUE),
		MAKEPROP(WPD_DEVICE_TYPE, WPD_DEVICE_TYPE_GENERIC)
	));

	SetState(SENSOR_STATE_READY);
	return hr;
}

void CSensorDevice::OnStateChange(SensorState, SensorState)
{
	//
	// since this is not a real device we don't notify anyone
	//
}

wstring CSensorDevice::GetId() const
{
	return WPD_DEVICE_OBJECT_ID;
}

wstring CSensorDevice::GetName() const
{
	return WPD_DEVICE_OBJECT_ID;
}

wstring CSensorDevice::GetParentId() const
{
	//
	// the "DEVICE" object does not have a parent
	//
	return L"";
}

GUID CSensorDevice::GetFunctionalObjectCategory() const
{
	return WPD_FUNCTIONAL_CATEGORY_DEVICE;
}
